package net.zjitc.linearlist.impl;

import net.zjitc.linearlist.MyLinearList;

import java.util.Scanner;

/**
 * Created by Administrator on 2017/3/8.
 */
public class TestList {
    public static void main(String[] args) {
        MyLinearList <Integer> list=new SeqList<Integer>(Integer.class,50);
        int []data={23,45,3,7,6,945};
        Scanner sc=new Scanner(System.in);
        System.out.println("-----------------------------");
        System.out.println("操作选项菜单");
        System.out.println("1.添加菜单");
        System.out.println("2.插入菜单");
        System.out.println("3.删除菜单");
        System.out.println("4.定位菜单");
        System.out.println("5.取表菜单");
        System.out.println("6.显示线菜单");
        System.out.println("0.退出");
        System.out.println("-----------------------------");
        char ch;
        do{
            System.out.println("请输入操作选项");
            ch=sc.next().charAt(0);
            switch (ch){
                case '1':
                    for (int i=0;i<data.length;i++){
                        list.add(data[i]);
                    }
                    System.out.println("添加操作成功");
                    break;
                case '2':
                    System.out.println("请输入要插入的位置");
                    int loc=sc.nextInt();
                    System.out.println("请输入要插入该位置的值");
                    int num=sc.nextInt();
                    list.add(loc-1,num);
                    System.out.println("插入成功");
                    break;
                case '3':
                    System.out.println("请输入要删除的元素的位置");
                    loc=sc.nextInt();
                    list.remove(loc-1);
                    System.out.println("删除操作成功");
                    break;
                case '4':
                    System.out.println("请输入查找的元素");
                    num=sc.nextInt();
                    System.out.println(num+"在列表中的位置为："+(list.indexOf(num)+1));
                    break;
                case '5':
                    System.out.println("请输入要查找的元素：");
                    loc=sc.nextInt();
                    System.out.println(loc+"位置上的元素为："+list.get(loc-1));
                    break;
                case '6':
                    System.out.println("线性表中的元素有：");
                    for (int i=0;i<list.getSize();i++){
                        System.out.println(list.get(i)+"");
                    }
                    System.out.println();
                    break;
            }
        }while (ch!='0');
        sc.close();
    }
}
